package leetcode;

import java.util.HashSet;
import java.util.Set;

public class Pro3 {
    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubstring("abcabcbb"));
    }

    public static int lengthOfLongestSubstring(String s) {
        int len = s.length();
        if (len == 0) {
            return 0;
        }
        int res = 0;
        Set<Character> set = new HashSet<>();
        int l = 0;
        for (int r = 0; r < len; r++) {
            if (set.contains(s.charAt(l++))) {
                set.remove(s.charAt(l - 1));
            }
            set.add(s.charAt(r));
            res = Math.max(res, set.size());
        }
        return res;
    }
}
